//
//  U9TopicManager.m
//  U9WatchGame
//
//  Created by u9-baken on 2019/12/9.
//  Copyright © 2019 UUU9. All rights reserved.
//
//话题
#import "U9TopicManager.h"
#import "U9MessageListModel.h"
#import "U9TopicListModel.h"
#import "U9TopicDetailModel.h"

@implementation U9TopicManager

+ (void)getTopicListWithUserid:(NSString *)userid andSession:(NSString *)session andGameID:(NSString *)gid andPageNum:(NSString *)page andCompletionHandle:(void (^)(U9TopicListModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session];
    [self POST:[NSString stringWithFormat:@"%@%@?gid=%@&page=%@",Api_URL,kGetTopicList,gid,page]
    parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9TopicListModel *model = [U9TopicListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}

+ (void)getTopicDetailWithUserid:(NSString *)userid andSession:(NSString *)session andTopicID:(NSString *)topicid andGameID:(NSString *)gid andCompletionHandle:(void (^)(U9TopicDetailModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"userid=%@&sessionid=%@",userid,session];
    [self POST:[NSString stringWithFormat:@"%@%@?id=%@&gid=%@",Api_URL,kGetTopicDetail,topicid,gid]
           parameters:param
    completionHandler:^(id responseObj, NSError *error) {
        U9TopicDetailModel *model = [U9TopicDetailModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:model.error_msg];
        }
        complete(model,error);
    }];
}


//回复话题
+ (void)replyingTopicWithUserid:(NSString *)userid andSession:(NSString *)session andTopicID:(NSString *)topicID andContent:(NSString *)content andParentID:(NSString *)parentID andGameID:(NSString *)gID andCompletionHandle:(void (^)(U9MessageListModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"object_id=%@&parent_id=%@&content=%@&gid=%@&userid=%@&sessionid=%@",topicID,parentID,content,gID,userid,session];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@",Api_URL,kReplyToTopic]
    parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9MessageListModel *model = [U9MessageListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:@"error"];
        }
        complete(model,error);
    }];
}



+(void)getTopicReplyListWithTopicID:(NSString *)topicID andPage:(NSString *)p andCompletionHandle:(void (^)(U9MessageListModel *model, NSError *error))complete{
    NSString *param = [NSString stringWithFormat:@"object_id=%@",topicID];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@",Api_URL,kGetTopicReplyList]
    parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9MessageListModel *model = [U9MessageListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:@"error"];
        }
        complete(model,error);
    }];
}

//获取回复的回复
+(void)getCommentReplyListWithTopicID:(NSString *)topicID andReplyID:(NSString *)replyID andPage:(NSString *)p andCompletionHandle:(void (^)(U9MessageListModel *model, NSError *error))complete{
     NSString *param = [NSString stringWithFormat:@"object_id=%@&comment_id=%@&page=%@",topicID,replyID,p];
    [self POSTBase64:[NSString stringWithFormat:@"%@%@",Api_URL,kGetTopicReplyReplyList]
    parameters:param
completionHandler:^(id responseObj, NSError *error) {
        U9MessageListModel *model = [U9MessageListModel mj_objectWithKeyValues:responseObj];
        if (model.error_code != 0) {
            error = [self createError:@"error"];
        }
        complete(model,error);
    }];
}


@end
